<?php

namespace bee;
/**
 *
 * @author dzelenika
 *
 */
class radio extends widget
{
  public $onChangeFn;
//  public $drawMe;
 /**
 *
 * @var bool
 */
  public $__checked;
  public $boundVarValue;

  function __construct($name, &$bindValue = "", $value = "1", $id = "")
  { parent::__construct($name, $id);
    $this->boundVarValue = &$bindValue;
    $this->value = $value;
    $this->drawMe = true;

  }
/**
 *
 * @param array $evt
 */
  public function onDraw($evt)
  { $this->checked();
    $this->fillDSDoc();
  }

  /**
   *
   * @param sting $fillVar
   */
  public function fillDSDoc($fillVar = "")
  {
    $__DSDoc = XMLDataHub::getInstance();
    if($fillVar && $this->checked)
    { $__DSDoc->setVariable($fillVar, $this->value);
    }
    if($this->drawMe)
    {  $__DSDoc->setObject("widgets/" . $this->name, $this, false);
    }
  }

  public function checked($checked = NULL)
  { if($checked === null)
    { //echo "cNull $this->id $this->boundVarValue / $this->value, ";
      if($this->boundVarValue == $this->value)
      { //echo $this->id . ": " . $this->boundVarValue ." == " . $this->value . " / " . ($this->boundVarValue != $this->value) . " <br />";
        $this->__checked = true;
        return true;
      } else
      { $this->__checked = false;
        return false;
      }
    } else
    { if($checked)
      { $this->boundVarValue = $this->value;
        $this->__checked = true;
        //echo "! $this->boundVarValue !";
      } else
      { $this->boundVarValue = "";
        $this->__checked = false;
      }
    }
  }


}
